<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.math.BigDecimal" %>
<%--获取发票信息--%>
<%
    JSONObject dataJson = new JSONObject();
    RecordSet rs = new RecordSet();
    try {
        String invoicenumbers = "";
        String invoicetypes = "";
        String categorys = "";
        String taxrates = "";
        String taxs = "";
        String taxssum = "";
        String pricewithouttaxs = "";
        String taxincludedprices = "";
        String invoiceserviceyypes = "";
        String fylxs = "";
        String fphms = Util.null2String(request.getParameter("fphms"));
        String sqlwhere = Util.null2String(request.getParameter("sqlwhere"));
        String newfphms = "";
        String [] fphmsArr = fphms.split(",");
        for (String fphm:fphmsArr) {
            newfphms+="".equals(newfphms)?"'"+fphm+"'":",'"+fphm+"'";
        }
        rs.executeQuery("select invoicenumber,invoicetype,category,taxrate,tax,pricewithouttax," +
                "taxincludedprice,invoiceserviceyype,fylx from fnainvoiceledger " +
                "where invoicenumber in ("+newfphms+") " +sqlwhere+
                " order by instr('"+fphms+"',invoicenumber)");
        while (rs.next()) {
            String invoicenumber = Util.null2String(rs.getString("invoicenumber"));
            String invoicetype = Util.null2String(rs.getString("invoicetype"));
            String category = Util.null2String(rs.getString("category"));
            String taxrate = Util.null2String(rs.getString("taxrate"));
            String tax = Util.null2String(rs.getString("tax"));
            String fylx = Util.null2String(rs.getString("fylx"));
            String pricewithouttax = Util.null2String(rs.getString("pricewithouttax"));
            String taxincludedprice = Util.null2String(rs.getString("taxincludedprice"));
            String invoiceserviceyype = Util.null2String(rs.getString("invoiceserviceyype"));
            invoicenumbers +="".equals(invoicenumbers)?invoicenumber:","+invoicenumber;
            invoicetypes +="".equals(invoicetypes)?invoicetype:","+invoicetype;
            categorys +="".equals(categorys)?category:","+category;
            taxrates +="".equals(taxrates)?taxrate:","+taxrate;
            taxs +="".equals(taxs)?tax:","+tax;
            taxssum = bAdd(taxssum,tax);
            fylxs +="".equals(fylxs)?fylx:","+fylx;
            pricewithouttaxs +="".equals(pricewithouttaxs)?pricewithouttax:","+pricewithouttax;
            taxincludedprices +="".equals(taxincludedprices)?taxincludedprice:","+taxincludedprice;
            invoiceserviceyypes +="".equals(invoiceserviceyypes)?invoiceserviceyype:","+invoiceserviceyype;
        }
        dataJson.put("invoicenumbers", invoicenumbers);
        dataJson.put("invoicetypes", invoicetypes);
        dataJson.put("categorys", categorys);
        dataJson.put("taxrates", taxrates);
        dataJson.put("taxs", taxs);
        dataJson.put("taxssum", taxssum);
        dataJson.put("fylxs", fylxs);
        dataJson.put("pricewithouttaxs", pricewithouttaxs);
        dataJson.put("taxincludedprices", taxincludedprices);
        dataJson.put("invoiceserviceyypes", invoiceserviceyypes);
    } catch (Exception e) {
        e.printStackTrace();
    }

    out.print(dataJson.toJSONString());
%>
<%!
    /**
     * @Description: 为零判断
     */
    public static String isZero(String a) {
        if ("".equals(a)) {
            a = "0";
        }
        return a;
    }


    /**
     * @Description: 相加
     */
    public static String bAdd(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        String result;
        try {
            BigDecimal bg1 = new BigDecimal(a);
            BigDecimal bg2 = new BigDecimal(b);
            BigDecimal bd = bg1.add(bg2);
            result = bd.toString();
        } catch (NumberFormatException e) {
            result = "";
        }
        return result;
    }

%>